import request from '../../utils/request';
import { sign } from '../api';
import { stringify } from 'qs';

/* ******************** 购物分期订单 ******************** */

// 查询购物订单
export async function queryAllOrder(params) {
  return request(`/api/order/getOrderList?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

// 查询退款维权订单
export async function queryAllRefundOrder(params) {
  return request(`/api/order/afterSales/getAfterSalesList?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

//获取退款详情
export async function getBackProductDetail(params) {
  return request(`/api/order/afterSales/getBackProductDetail?${stringify(params)}&sign=${sign(params)}`);
}

// 查询分期待还
export async function queryInstalmentWaitPayOrder(params) {
  return request(`/api/bill/installment/waitRepayInstallmentList?${stringify(params)}&sign=${sign(params)}`);
}

// 查询分期已还
export async function queryInstalmentAlreadyPayOrder(params) {
  return request(`/api/bill/installment/repayedInstallmentList?${stringify(params)}&sign=${sign(params)}`);
}

// 查询分期待还统计
export async function waitRepayInstallmentCount(params) {
  return request(`/api/bill/installment/waitRepayInstallmentCount?${stringify(params)}&sign=${sign(params)}`);
}

// 查询分期已还统计
export async function repayedInstallmentCount(params) {
  return request(`/api/bill/installment/repayedInstallmentCount?${stringify(params)}&sign=${sign(params)}`);
}

// 还款
export async function addRepayItem(params) {
  return request(`/api/bill/repayItem/addInstallmentRepayItem?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 还款强制结清
export async function addRepayItemClear(params) {
  return request(`/api/bill/repayItem/installmentBillClear?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 根据orderId查询分期信息
export async function queryBillItemById(params) {
  return request(`/api/bill/installment/orderInstallmentBillInfo?${stringify(params)}&sign=${sign(params)}`);
}

// 根据orderId查询还款信息
export async function queryRepayItemById(params) {
  return request(`/api/bill/repayItem/installmentBillRepayItemList?${stringify(params)}&sign=${sign(params)}`);
}

/* ******************** 贷款分期订单 ******************** */

// 查询提现订单
export async function queryWithdrawBill(params) {
  return request(`/api/bill/withdraw/withdrawItemList?${stringify(params)}&sign=${sign(params)}`);
}


// 提现账单手动打款
export async function manualTransfer(params) {
  return request(`/api/bill/withdraw/manualTransfer?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}



// 提现账单手动打款
export async function manualTransferSuccess(params) {
  return request(`/api/bill/withdraw/withdrawItemLendSuccess?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 提现账单手动打款
export async function manualTransferFail(params) {
  return request(`/api/bill/withdraw/withdrawItemLendFail?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 还款
export async function addWithdrawRepayItem(params) {
  return request(`/api/bill/repayItem/addWithdrawRepayItem?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 还款强制结清
export async function addWithdrawRepayItemClear(params) {
  return request(`/api/bill/repayItem/withdrawBillClear?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 根据withdrawId查询还款信息
export async function queryRepayItemByWithdrawId(params) {
  return request(`/api/bill/repayItem/withdrawRepayItemList?${stringify(params)}&sign=${sign(params)}`);
}

//获取用户银行卡信息-sdfz
export async function getUserBankCardWithdraw(params) {
  return request(`/api/bill/withdraw/getUserBankCard?${stringify(params)}&sign=${sign(params)}`);
}

//获取用户银行卡信息-想美/信花花/有点
export async function getUserBankCardLoan(params) {
  return request(`/api/loan/getUserBankCard?${stringify(params)}&sign=${sign(params)}`);
}

//自动打款开关状态获取
export async function getAutoTransferStatus(params) {
  return request(`/api/user/systemConfig/getAutoTransferStatus?${stringify(params)}&sign=${sign(params)}`);
}

//开启或关闭自动打款
export async function postAutoTransferSwitch(params) {
  return request(`/api/user/systemConfig/autoTransferSwitch?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 易宝提现订单打款
export async function manualTransferYb(params) {
  return request(`/api/pay/withdraw?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

export async function batchWithdraw(params) {
  return request(`/api/pay/batchWithdraw?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

export async function smartBatchWithdraw(params) {
  return request(`/api/pay/smartBatchWithdraw?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

/* ******************** 想美借款订单 ******************** */

// 查询借款订单
export async function loanItemList(params) {
  return request(`/api/loan/loanItemList?${stringify(params)}&sign=${sign(params)}`);
}


// 借款账单手动打款
export async function loanManualTransfer(params) {
  return request(`/api/loan/manualTransfer?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}



// 借款账单手动打款
export async function loanManualTransferSuccess(params) {
  return request(`/api/loan/loanItemLendSuccess?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 借款账单手动打款
export async function loanManualTransferFail(params) {
  return request(`/api/loan/loanItemLendFail?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 还款
export async function addLoanRepayItem(params) {
  return request(`/api/loan/addLoanRepayItem?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 还款强制结清
export async function addLoanRepayItemClear(params) {
  return request(`/api/loan/loanItemForceClear?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

// 根据loanId查询还款信息
export async function queryRepayItemByLoanId(params) {
  return request(`/api/loan/loanRepayItemList?${stringify(params)}&sign=${sign(params)}`);
}


// 易宝提现订单打款
export async function loanManualTransferYb(params) {
  return request(`/api/pay/xbeautyWithdraw?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

//易宝提现订单批量打款
export async function xbeautyBatchWithdraw(params) {
  return request(`/api/pay/xbeautyBatchWithdraw?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

//易宝提现订单智能批量打款
export async function xbeautySmartBatchWith(params) {
  return request(`/api/pay/xbeautySmartBatchWith?sign=${sign(params)}`, {
    method: 'POST',
    body: params,
  });
}

//=========sdfz=============
//待放款统计

export async function waitLendWithdrawCount(params) {//待放款统计
  return request(`/api/bill/withdraw/waitLendWithdrawCount?${stringify(params)}&sign=${sign(params)}`);
}
//放款失败统计
export async function lendFailWithdrawCount(params) {//待放款统计
  return request(`/api/bill/withdraw/lendFailWithdrawCount?${stringify(params)}&sign=${sign(params)}`);
}

//待还款统计
export async function WaitRepayWithdrawCount(params) {//待放款统计
  return request(`/api/bill/withdraw/waitRepayWithdrawCount?${stringify(params)}&sign=${sign(params)}`);
}

//已还款统计
export async function HaveRepayedWithdrawCount(params) {//待放款统计
  return request(`/api/bill/withdraw/repayedWithdrawCount?${stringify(params)}&sign=${sign(params)}`);
}

//=========想美=============
//待放款统计

export async function waitLendLoanCount(params) {//待放款统计
  return request(`/api/loan/waitLendLoanCount?${stringify(params)}&sign=${sign(params)}`);
}
//放款失败统计
export async function lendFailLoanCount(params) {//待放款统计
  return request(`/api/loan/lendFailLoanCount?${stringify(params)}&sign=${sign(params)}`);
}

//待还款统计
export async function waitRepayLoanCount(params) {//待放款统计
  return request(`/api/loan/waitRepayLoanCount?${stringify(params)}&sign=${sign(params)}`);
}

//已还款统计
export async function repayedLoanCount(params) {//待放款统计
  return request(`/api/loan/repayedLoanCount?${stringify(params)}&sign=${sign(params)}`);
}

//=============end=============

//充值
export async function topupRecharge(params) {
  return request(`/api/pay/topup?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: params,
  });
}

//充值记录
export async function getTopupList(params) {//待放款统计
  return request(`/api/pay/topupList?${stringify(params)}&sign=${sign(params)}`);
}

//执行代扣
export async function postWithhold(params) {
  return request(`/api/pay/batchWithholding?sign=${sign(params)}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: params,
  });
}
